$(() => {
    let nearList = localStorage.getItem("nearList");
    if (!!nearList) {
        console.log("存储");
        JSON.parse(nearList).map(v => {
            accomInclude = v.accomInclude == undefined ? '' : v.accomInclude;
            let ele = `
                <li>
                    <a href="./details/index.html?routeId=${v.id}&&id=${v.ttsEnid}&&t3id=${v.teamTypeId}">
                        <div class="left">
                            <div class="flag">${v.extendFunction}</div>
                            <img src="${v.randomImgUrl}" alt="...">
                        </div>
                        <div class="right">
                            <div class="title">${v.hotSpringName}</div>
                            <div class="desc"><span>${v.hotSpringSubTitle} | ${accomInclude}</span></div>
                            <div class="price">￥ <span style="font-size: 14px; color: #ff6868; font-weight: bold;">${v.price} </span><span>起/人</span></div>
                        </div>
                    </a>
                </li>
            `;
            $(ele).appendTo($("article>ul"));
        })
        $(".loading").css("display", "none");
    } else {
        // 根据定位获得当前城市景点数据
        let currentCity = null;
        AMap.plugin('AMap.Geolocation', function () {
            var geolocation = new AMap.Geolocation({
                // 是否使用高精度定位，默认：true
                enableHighAccuracy: true,
                // 设置定位超时时间，默认：无穷大
                timeout: 10000,
                // 定位按钮的停靠位置的偏移量，默认：Pixel(10, 20)
                buttonOffset: new AMap.Pixel(10, 20),
                //  定位成功后调整地图视野范围使定位位置及精度范围视野内可见，默认：false
                zoomToAccuracy: true,
                //  定位按钮的排放位置,  RB表示右下
                buttonPosition: 'RB'
            })

            geolocation.getCurrentPosition()
            AMap.event.addListener(geolocation, 'complete', onComplete)
            AMap.event.addListener(geolocation, 'error', onError)

            function onComplete(data) {
                // data是具体的定位信息
                console.log("data =>", data);
                currentCity = data.addressComponent.city;
                getCurrentCityData();
            }

            function onError(data) {
                // 定位出错
            }
        });

        let getCurrentCityData = () => {
            $.ajax({
                url: 'https://touch.dujia.qunar.com/list',
                type: 'GET',
                dataType: 'jsonp',
                data: {
                    modules: 'list,bookingInfo,activityDetail',
                    // dep: '北京',
                    query: currentCity,
                    type: 'all',
                    dappDealTrace: true,
                    it: 'a_sug_more',
                    itineraryday: '1,2,3',
                    date: '',
                    ddf: true,
                    needNoResult: true,
                    originalquery: currentCity,
                    width: '480',
                    height: '320',
                    quality: '90',
                    limit: '0,20',
                    includeAD: true,
                    qsact: 'search',
                    filterTagPlatform: 'mobile_touch',
                },
                success: function (data) {
                    console.log(data);
                    let accomInclude = null;
                    let info = data.data.list.results;
                    info.map(v => {
                        accomInclude = v.accomInclude == undefined ? '' : v.accomInclude;
                        let ele = `
                        <li>
                            <a href="./details/index.html?routeId=${v.id}&&id=${v.ttsEnid}&&t3id=${v.teamTypeId}">
                                <div class="left">
                                    <div class="flag">${v.extendFunction}</div>
                                    <img src="${v.randomImgUrl}" alt="...">
                                </div>
                                <div class="right">
                                    <div class="title">${v.hotSpringName}</div>
                                    <div class="desc"><span>${v.hotSpringSubTitle} | ${accomInclude}</span></div>
                                    <div class="price">￥ <span style="font-size: 14px; color: #ff6868; font-weight: bold;">${v.price} </span><span>起/人</span></div>
                                </div>
                            </a>
                        </li>
                    `;
                        $(ele).appendTo($("article>ul"));
                    })
                    localStorage.setItem("nearList", JSON.stringify(info));
                    $(".loading").css("display", "none");
                },
                error: function (err) {
                    console.log(err);
                }
            })
        };
    }
})